/*
 * Copyright the original author or authors.
 * 
 * Licensed under the MOZILLA PUBLIC LICENSE, Version 1.1 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *	  http://www.mozilla.org/MPL/MPL-1.1.html
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.googlecode.milib.actionControll.observe {
	import com.googlecode.milib.base.IMLBroadcasterListener;
	import com.googlecode.milib.base.MLBroadcastClass;
	import com.googlecode.milib.service.singleton.EnterFrameService;
	import com.googlecode.milib.vo.MLEventInfo;

	/**
	 * @author Marek Brun @ MindChili
	 */
	public class WhenAnyActionRunningEnterFrame extends MLBroadcastClass implements IMLBroadcasterListener {
		
		public const event_SomeActionIsRunning : String = 'SomeActionIsRunning';
		public const event_AllActionsIsNotRunning : String = 'AllActionsIsNotRunning';
		public const event_EnterFrameWhenAnyActionRunning : String = 'EnterFrameWhenAnyActionRunning';
		
		private var anyActionRunning:AnyActionIsRunningObserver;
		private var efb:EnterFrameService;

		public function WhenAnyActionRunningEnterFrame(actions:Array) {
			anyActionRunning=new AnyActionIsRunningObserver();
			anyActionRunning.addListener(this);
			anyActionRunning.collection.addValues(actions);
			efb=EnterFrameService.getInstance();
		}
		
//********************************************************************************************
//		events for WhenAnyActionRunningEnterFrame
//********************************************************************************************
		public function onEvent(ev:MLEventInfo):void {
			switch(ev.hero){
				case anyActionRunning:
					switch(ev.event) {
						case anyActionRunning.event_SomeActionIsRunning:
							efb.addListener(this);
							broadcastEvent(event_SomeActionIsRunning);
							break;
						case anyActionRunning.event_AllActionsIsNotRunning:
							efb.removeListener(this);
							broadcastEvent(event_AllActionsIsNotRunning);
							break;
					}
					break;
				case efb:
					switch(ev.event) {
						case efb.event_EnterFrame:
							broadcastEvent(event_EnterFrameWhenAnyActionRunning);
							break;
					}
					break;
			}
		}
		
	}
}
